package com.a9development.jpolynomial;

import java.util.regex.*;

/**
 * A class for storing and manipulating monomials. It allows for
 * various algebra operations to be done as well as a few other
 * functions.
 *  
 * @author		Daniel Kotowski
 * @version		%I%, %G%
 */
public class Monomial {
	private Integer[] powers;
	private String[] variables;
	
	/**
	 * Default constructor.
	 * 
	 * Input is of the form "x1^r1 * x2^r2 * x3^r3" and so on
	 * until you have listed all the variables you want. The
	 * regular expressions used to match each term xn^rn are
	 * "[x\d+\^\d*][\*x\d+\^\d*]*" and
	 * "[[a-z]\^\d*][\*[a-z]\^\d*]*".
	 * 
	 * Example input:
	 * "x1^4*x2*x4^9"
	 * would be recognized as a monomial in 4 variables.
	 * 
	 * @param s		the string to become a monomial
	 */
	public Monomial(String s) {
		//TODO parse s into a monomial
		// 1. strip whitespace characters and change to all lowercase
		// 2. check with regex for valid input
		// 3. if valid, parse
		s = s.replaceAll("\\s+", "").toLowerCase();
		Pattern pattern1 = Pattern.compile("[x\\d+\\^\\d*][\\*x\\d+\\^\\d*]*");
		Pattern pattern2 = Pattern.compile("[[a-z]\\^\\d*][\\*[a-z]\\^\\d*]*");
		
		Matcher matcher1 = pattern1.matcher(s);
		Matcher matcher2 = pattern2.matcher(s);
				
	}
	
	/**
	 * Alternate constructor that allows for setting the number of
	 * variables the monomial is in.
	 * 
	 * @param s			the string to become a monomial
	 * @param varCount	the number of variables the monomial is in
	 */
	public Monomial(String s, int varCount) {
		//TODO parse s into a monomial in 'varCount' variables
		
	}
	
	public int totalDegree() {
		int td = 0;
		for (int i = 0; i < powers.length; i++)
			td += powers[i];
		
		return td;
	}
	
	public boolean lessThan(Monomial m, MonomialOrdering o) {
		boolean lt = false;
		switch(o) {
		//TODO Write code to do orderings
		case LEXICOGRAPHIC: break;
		default: break;
		}
		
		return lt;
	}
	
	public boolean greaterThan(Monomial m, MonomialOrdering o) {
		boolean gt = false;
		switch (o) {
		//TODO Write code to do orderings
		case LEXICOGRAPHIC: break;
		default: break;
		}
		
		return gt;
	}
}
